<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/static/commons/taglibs.jsp"%>
<%@ include file="/static/commons/meta.jsp"%>
<%@ include file="/static/commons/jquery-easyui.jsp"%>
<html >
	 <head>
 		<title>${title }</title>
 		 <link rel="stylesheet" href="${ctx }/static/styles/basic/basic.css" />
		 <link rel="stylesheet" href="${ctx }/static/styles/frame/main.css" />
		 <link rel="stylesheet" href="${ctx }/static/styles/frame/searchBtn.css" />
		 <link rel="stylesheet" href="${ctx }/static/styles/frame/searchCondition.css" />
	    <!-- js -->
 		<script type="text/javascript" src="${ctx}/static/scripts/check_all.js"></script>
 		<script type="text/javascript" src="${ctx}/static/scripts/set_select.js"></script>
 		<script type="text/javascript" src="${ctx}/static/scripts/waiting.js"></script>
 		<script type="text/javascript" src="${ctx}/static/scripts/crud.js"></script>
 		<script type="text/javascript" src="${ctx}/static/scripts/util.js"></script>
		<script type="text/javascript" src="${ctx}/static/scripts/WdatePicker/WdatePicker.js"></script>
	</head>
  <body onload="init()">
		<form action="${ctx}/buyApply/list" method="post">
  			<input type="hidden" name="RequestVerificationToken" value="${RequestVerificationToken}" />
			<div class="width_100 group_box">
				<div class="group_search width_100">
					<vvise:select id="status" name="p_status" sqlname="getCodeData" sqlparam="buy_status" displayText="状态" ifSearch="true"   />
					<vvise:searchInput id="supplierName" name="p_supplierName" displayText="供应商" />
					<vvise:searchInput id="startDate" name="p_startDate" defVal="${startDate}" 
			                endId="endtDate" endName="p_endtDate" endDefVal="${endDate}"
			                 type="time2" displayText="申请日期" dateFormat="yyyy-MM-dd"/>
               	 	<div class="clear_both"></div>
				</div>
				<vvise:funMenu menuId="${menuId}" />
			</div>
        </form>
        <div class="listFrame">
        	<iframe name="listFrame" id="listFrame" frameBorder="0"
				scrolling="auto" style="width: 100%;height:100%;"></iframe>
        </div>
	</body>
	<script language="javaScript">
  		var headers = {};
		headers['__RequestVerificationToken'] = "${RequestVerificationToken}";
			//回车事件
		document.onkeydown = keyKistener;
		function keyKistener(e){
			e = e ? e:event;
			if(e.keyCode == 13){
				try{
					search();
				}catch(e){}
			}
		}
		function init(){
			set_iframe_h();
			$(window).resize(function(){
				set_iframe_h();
			});
			search();
			$('.easyui-combobox').combobox();
		}
		//设置ifream 高度
		function set_iframe_h(){
			var win_height  = $(window).height();
			var func_line_h = $('.group_box').outerHeight(true);
			var list_height = win_height - func_line_h;
			$('.listFrame').css('height',list_height-10);
		}
		function search(){
			waiting();
			document.forms[0].target = "listFrame";
			document.forms[0].submit();
		}
		
		function create(buyId){
			if(parent.isEmpty(buyId)){
				buyId = "";
			}else{
				var status = listFrame.document.getElementById('status_'+buyId).value;
				if(status != 10){
					parent.alertMsg('采购单已审核，无法修改！','warning',function(){
					});
					return;
				}
			}
				
			var pp = parent;
			doCreate("采购信息",pp.width3+100,480,"${ctx}/buyApply/edit?buyId="+buyId);
		}
		
		function save(){
			var pp = parent;
			var editFrame = pp.winFrame;
			var buyId = editFrame.$('#buyId').val();
			var buyUse = editFrame.$('#buyUse').val();
			
			if(!pp.validData("buyUse","请选择用途！"))
				return;
				
			if(!pp.validData("supplier","请输入供应商名称！"))
				return;
			
			if(!pp.validData("supplierAddr","请输入供应商地址！"))
				return;
			
			if(!pp.validData("supplierLinkman","请输入联系人！"))
				return;
			
			if(!pp.validData("supplierPhone","请输入联系电话！"))
				return;
				
			if(!pp.validData("arriveDate","请选择到货日期！"))
				return;
				
			if(!pp.validData("applyReason","请输入申请理由！"))
				return;
			
			if(buyUse == 2){
				if(!pp.validData("customer","请输入客户单位！"))
					return;
				
				if(!pp.validData("custAddr","请输入客户地址！"))
					return;
				
				if(!pp.validData("custLinkman","请输入联系人！"))
					return;
				
				if(!pp.validData("custPhone","请输入联系电话！"))
					return;
			}	
			var proClass = editFrame.$(".proClass");
			if(proClass.length == 0){
				pp.alertMsg('请添加采购产品！','warning',function(){
				});
				return;
			}
			
			var ifSave = true;
			proClass.each(function(){
       			var idx = $(this).attr("idx");
       			var xuhao = editFrame.$("#xuhao_" + idx).html();
       			var productName = editFrame.$("#productName_"+idx).val();
       			if(productName == ""){
       				pp.alertMsg('第【'+ xuhao +'】行采购产品名称不能为空！','warning',function(){
					 	editFrame.$("#productName_"+idx).focus();
					});
					ifSave = false;
					return false;
       			}
       			var model = editFrame.$("#model_"+idx).val();
       			if(model == ""){
       				pp.alertMsg('第【'+ xuhao +'】行型号不能为空！','warning',function(){
					 	editFrame.$("#model_"+idx).focus();
					});
					ifSave = false;
					return false;
       			}
       			var num = editFrame.$("#num_"+idx).val();
       			if(num == ""){
       				pp.alertMsg('第【'+ xuhao +'】行数量不能为空！','warning',function(){
					 	editFrame.$("#num_"+idx).focus();
					});
					ifSave = false;
					return false;
       			}
       			var unitPrice = editFrame.$("#unitPrice_"+idx).val();
       			if(unitPrice == ""){
       				pp.alertMsg('第【'+ xuhao +'】行单价不能为空！','warning',function(){
					 	editFrame.$("#unitPrice_"+idx).focus();
					});
					ifSave = false;
					return false;
       			}
       		}); 
       		
       		if(!ifSave){
       			return;
       		}
			
			doSave("${ctx}/buyApply/save",buyId);
		}
		
		function view(buyId){
			var pp = parent;
			doView("采购信息",pp.width3+100,480,"${ctx}/buyApply/edit?buyId="+buyId+"&view=view");
		}
		
		function removeF(){
			var pp = parent;
			var ids = "";
			var ecForm = listFrame.document.all.ec;
			if(!checkSelect(ecForm.id,true))
				return;
			ids = get_checkbox_values(ecForm.id,',');
			
			for(var i in ids.split(',')){
				var buyId = ids.split(',')[i];
				var status = listFrame.document.getElementById('status_'+buyId).value;
				if(status != 10){
					parent.alertMsg('部分采购单已审核，无法删除！','warning');
					return;
				}
			}
			
			pp.confirmMsg("确定要删除吗？",function(){
				var urls = "${ctx}/buyApply/delete";
			    var params = "buyIds="+ids;
			    executeAjax(urls,params,function(data){
				    if(data != 'error'){
				    	pp.$.messager.alert('操作提示', "操作成功！", "info",function(){
				    		listRefresh();
				    	});
					}else{
						pp.$.messager.alert('操作提示',"操作失败！","error");
					}
			    });
			});
		}
		function ticket(){
			var ecForm = listFrame.document.all.ec;
			if(!checkSelect(ecForm.id,false,'付款'))
				return;
			var buyId = get_checkbox_value(ecForm.id);
			var status = listFrame.document.getElementById('status_'+buyId).value;
			if(status != 20){
				parent.alertMsg('采购单未审核，无法付款！','warning',function(){
				});
				return;
			}
			var pp = parent;
			doCreate("采购信息",pp.width3+100,480,"${ctx}/buyApply/edit?buyId="+buyId);
		}
		</script>
</html>